package org.springframework.security.core.context;

import java.util.function.Supplier;

/**
 * @author Dillon
 * @date 2024/6/28
 * @slogan 致敬大师 致敬未来的你
 * @desc springSecurity 登录成功存储登录表示策略接口
 */
public interface SecurityContextHolderStrategy {

	/**
	 * 清除 SecurityContext 缓存
	 */
	void clearContext();

	/**
	 * 获取 SecurityContext 缓存
	 * @return SecurityContext
	 */
	SecurityContext getContext();

	/**
	 * 获取一个延时加载的  SecurityContext
	 * @return Supplier<SecurityContext>
	 */
	default Supplier<SecurityContext> getDeferredContext() {
		return this::getContext;
	}

	/**
	 * 设置  SecurityContext
	 * @param context SecurityContext
	 */
	void setContext(SecurityContext context);

	/**
	 * 设置一个延时加载的  SecurityContext
	 * 在第一次调用该方法时进行  SecurityContext 获取
	 * @param deferredContext SecurityContext
	 */
	default void setDeferredContext(Supplier<SecurityContext> deferredContext) {
		setContext(deferredContext.get());
	}

	/**
	 * 创建 SecurityContext 默认实现 SecurityContextImpl
	 * @return SecurityContextImpl
	 */
	SecurityContext createEmptyContext();

}
